
#include "Engine.chs.h"
#include <stdint.h>

typedef int64_t WAMEntry;

typedef WAMEntry *WAMRef;


/* XXX - duplicate haskell entries exist, we will need to work out which
   we're using in the end ... */

#define HEAPSIZE  4000000
#define CODESIZE  4000000
#define TRAILSIZE 1000000

struct WAMData {
  WAMEntry heap[HEAPSIZE];
  WAMEntry code[CODESIZE];

  /* codeaux ?? */

#define heapTop 0
#define codeTop 1
#define envTop 2
#define choiceBottom 3
#define choice 4
#define cutchoice 5
#define dedchoice 6
#define pc 7
#define contp 8
#define sreg 9
#define AUXREGSIZE 10
  /* heapSize, codeSize, mode */
  WAMRef auxRegisters[AUXREGSIZE];

  int mode;
  /* indices we will leave in haskell ... */
  WAMRef trail[TRAILSIZE];
  WAMRef trailtop;
  /* call stack in haskell */

  /* randtable and counters in haskell */

};

struct ICCount {
  uint64_t inductiveCount;
  uint64_t deductiveCount;
  uint64_t globalCount;
};



struct WAMData *newWAMData();
inline WAMRef getAux(struct WAMData *s, int i);
inline void setAux(struct WAMData *s,int i,WAMRef v);

void incPC(void *wd);
typedef uint64_t WAMOpRaw;
WAMOpRaw getCodeEntryInst(void *wd);
WAMOpRaw getCodeEntryAux(void *wd);
int getQueryResult(void *wd);
int getOp(WAMOpRaw);
int isAuxOp(WAMOpRaw);

void execCodeEntryInst(void *wd,WAMOpRaw code);
void execCodeEntryInstAux(void *wd,WAMOpRaw code, WAMOpRaw codeaux);

